function getCookie(id){
	stat_str=Get_Cookie(id);
	return stat_str;
}

function setCookie(name,value){
	Set_Cookie(name,value);
}

function addAsFriend(event,user_id, username){
	event.stopPropagation();
	jQuery.post("actionService.php",{"method": "addAsFriend", "userid": user_id}, function(data){
				var message;
				if(data.IsSuccess){
					jQuery("#"+user_id+"_friendStar").removeClass('star_not_friend').addClass('star_friend');
					message = "User "+username+" is now in your friend list";
				}else{
					message = "Something went wrong, please try again later";
				}
				showWarning(message);
			}
	,"json");
}
function removeFriend(event,user_id, username){
	event.stopPropagation();
	jQuery.post("actionService.php",{"method": "removeFriend", "userid": user_id}, function(data){
				var message;
				if(data.IsSuccess){
					jQuery("#"+user_id+"_friendStar").removeClass('star_friend').addClass('star_not_friend');
					message = "User "+username+" is now out of your friend list";
				}else{
					message = "Something went wrong, please try again later";
				}
				showWarning(message);
			}
	,"json");
}

function setPhonoSessionId(sessionId){
	jQuery.post("actionService.php",{"method": "addPhonoSessionId","sessionId":sessionId}, function(data){
//		showWarning(data.Msg);
	},"json");
}

function getPhonoSessionId(userId){
	jQuery.post("actionService.php",{"method": "getPhonoSessionId","userId":userId}, function(data){
			
	},"json");
}

function friendActionClick(event,user_id, username){
	event.stopPropagation();
	window.location.href = 'http://noobskool.net/newsite/coachdetails.php?coach_id='+user_id;
}
function filterFriend(event,letter){
	event.stopPropagation();
	if(letter == 'All'){
		jQuery('[class^="players_link_"]').fadeOut('fast',function(){});
		jQuery('[class^="players_link_"]').fadeIn('fast');
		return;
	}
	
	var select = 'players_link_'+letter;
	jQuery('[class^="players_link_"]').fadeOut('fast',function(){});
	jQuery('.'+select).fadeIn('fast');
	
}
function submitbyenter(formid,myfield, e, dec){
	var key;
	var keychar;
	if (window.event)
	key = window.event.keyCode;
	else if (e)
	key = e.which;
	else
	return true;		
	if (key==13)
	{		
		GetLogin('frmLogin');		
	}	
}

function submit_frm(){	
	GetLogin('frmLogin');			
}

function open_lostPwd(){
  jQuery('#overlay').fadeIn("fast",function(){
		var width = jQuery("#lostPwd").width();
		jQuery("#lostPwd").css('margin-left', -(width/2)); 
		jQuery('#lostPwd').fadeIn("fast");
	});
}  

function submitenter(formid,myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event)
	key = window.event.keyCode;
	else if (e)
	key = e.which;
	else
	return true;		
	if (key==13)
	{		
		GetPwd('frmLostpwd',function(){jQuery('#overlay').fadeOut('fast')});		
	}	
}
function Get_pwd(){	
  GetPwd('frmLostpwd',function(){jQuery('#overlay').fadeOut('fast')});	
}

function openLogin(){

	  jQuery('#overlay').fadeIn("fast",function(){
		var width = jQuery("#loginwindow").width();
		jQuery("#loginwindow").css('margin-left', -(width/2)); 
		jQuery('#loginwindow').fadeIn("fast",function(){
			jQuery('#email').focus(function(){ if( jQuery(this).val()== 'Enter Your Email' ) jQuery(this).val('');});
			jQuery('#email').blur(function(){ if( jQuery(this).val()== '' ) jQuery(this).val('Enter Your Email');});
			jQuery('#password').focus(function(){ if( jQuery(this).val()== 'password' ) jQuery(this).val('');});
			jQuery('#password').blur(function(){ if( jQuery(this).val()== '' ) jQuery(this).val('password');});
			jQuery('#email_id').focus(function(){ if( jQuery(this).val()== 'Enter Your Email' ) jQuery(this).val('');});
			jQuery('#email_id').blur(function(){ if( jQuery(this).val()== '' ) jQuery(this).val('Enter Your Email');});
		});
		
	  });
}
function openRegister(){
	 jQuery('#overlay').fadeIn("fast",function(){
		var width = jQuery("#registerwindow").width();
		jQuery("#registerwindow").css('margin-left', -(width/2)); 
		jQuery('#registerwindow').fadeIn("fast",function(){
			document.getElementById('captcha').src='captcha.php?'+Math.random();
		});
	 });
}

function CheckFields(){
		  
	if(jQuery("#register-email").val()=="")
		 jQuery("#register-email").attr('style','border:1px solid #FF0000');
	if(jQuery("#name").val()=="")
		 jQuery("#name").attr('style','border:1px solid #FF0000');
	if(jQuery("#password1").val()=="")
		 jQuery("#password1").attr('style','border:1px solid #FF0000');
	if(jQuery("#password2").val()=="")
		 jQuery("#password2").attr('style','border:1px solid #FF0000');
	if(jQuery("#txtCaptcha").val()=="")	
		 jQuery("#txtCaptcha").attr('style','border:1px solid #FF0000');
	 
	if(!jQuery("#register-email").emailCheck() || document.getElementById('register-email').value=='' ) {
	
		jQuery('#FormErrorMsg').show();
		jQuery('#FormErrorMsg').html("Please Enter a Valid email");
		jQuery("#register-email").attr('style','border:1px solid #FF0000');
		return false;
	}
	if(document.getElementById('name').value==''){
		jQuery('#FormErrorMsg').show();
		jQuery('#FormErrorMsg').html("Please enter your UserID");
		jQuery("#name").attr('style','border:1px solid #FF0000');
		return false;
	}
	if(document.getElementById('password1').value=='' ) {
	
		jQuery('#FormErrorMsg').show();
		jQuery('#FormErrorMsg').html("Please Enter a password");
		jQuery("#password1").attr('style','border:1px solid #FF0000');
		return false;
	}
	else
	{
		if(jQuery('#password1').val().length<7){
		 jQuery('#FormErrorMsg').show();
		 jQuery('#FormErrorMsg').html("Password Minimum <b>7 Characters</b>");
		 jQuery("#password1").attr('style','border:1px solid #FF0000');
		 return false;
		} 
	}
	if(document.getElementById('password2').value=='' ) {
		jQuery('#FormErrorMsg').show();
		jQuery('#FormErrorMsg').html("Please Enter confirm password");
		jQuery("#password2").attr('style','border:1px solid #FF0000');
		return false;
	}
	if(document.getElementById('password2').value!=document.getElementById('password1').value){
		jQuery('#FormErrorMsg').show();
		jQuery('#FormErrorMsg').html("Password doesn't match");
		jQuery("#password2").attr('style','border:1px solid #FF0000');
		return false;
	}
	register();
}

function clearFields(){
	var form = document.getElementById('Contact');
	for(var i = 0; i< form.children[0].elements.length; i++){
		form.children[0].elements[i].value = "";
	}
}

function register(){
	var url = "registration.php";				
	jQuery.post(url, jQuery('#registerForm').serializeArray(),function(data){
		if(!data.IsSuccess){
			jQuery('#FormErrorMsg').html(data.Message);
			jQuery('#FormErrorMsg').show();
		}else
			jQuery('#registeroverlay').fadeIn('fast',function(){jQuery('#registerSuccesswindow').fadeIn('fast',function(){jQuery('#closeRegisterBtn').fadeOut('slow');});});
	},"json");
}	

function closeRegister(event){
	event.stopPropagation();
	jQuery('#registerwindow').fadeOut("fast", function(){jQuery('#overlay').fadeOut('fast',function(){document.location.href='dashboard.php';})});
}
 
function closeOpen(close, open,event){
	event.stopPropagation();
	jQuery("#"+close).fadeOut("fast", function(){
		var width = jQuery("#"+open).width();
		jQuery("#"+open).css('margin-left', -(width/2)); 
		jQuery("#"+open).fadeIn();
	});
} 
function showWarning(message, img, callback){
	var html = [];
	html.push('<div class="modalpopup" id="chiron_warning" style="display: block; height: 150px; width: 400px; margin-top: -150px;margin-left: -200px; position: fixed">');
	if(!img || img == '')
		img = "";
	else
		img = '<tr><td rowspan="3">'+img+'</td></tr>'
	html.push('<table style="width: 100%;">'+img+'<tr align="center" valign="middle"><td style="height: 95px;" ><span class="time_calendar_warnig_text">');
	html.push(message);
	html.push('</span></td></tr><tr align="center" valign="middle"><td style="height: 35px;">');
	if(!callback)
		callback = "";
	html.push('<div class="button-flex" style="margin: 0 auto;width: 70px;"><a href="#" class="button" onclick="jQuery(\'#chiron_warning\').remove(); jQuery(\'#overlay\').fadeOut(\'fast\');'+callback+'"><span>close</span></a></div></td></tr>');
	var warnig = jQuery(html.join("")).draggable();
	jQuery("body").append(warnig);
	jQuery("#overlay").fadeIn('fast');
	return html.join("");

}
function showYesNo(message, img, id, callbackYes, callbackNo, yesText, noText, yesClass, noClass){
	console.log('*************** showYesNo ****************');
	var html = [];
	if(!id)
		id = "chiron_yesno";
	html.push('<div class="modalpopup" id="'+id+'" style="display: block; height: 150px; width: 400px; margin-top: -150px;margin-left: -200px; position: fixed">');
	if(!img || img == '')
		img = "";
	else
		img = '<tr><td rowspan="3">'+img+'</td></tr>'
	html.push('<table style="width: 100%;">'+img+'<tr align="center" valign="middle"><td style="height: 95px;" ><span class="time_calendar_warnig_text">');
	html.push(message);
	html.push('</span></td></tr><tr align="center" valign="middle"><td style="height: 35px;">');
	if(!callbackYes)
		callbackYes = "";
	if(!callbackNo)
		callbackNo = "";
	if(!yesText)
		yesText = "Yes";
	if(!noText)
		noText = "No";
	if(!yesClass)
		yesClass = "button";
	if(!noClass)
		noClass = "button";
	
	html.push('<div class="button-flex" style="margin: 0 auto;"><a href="#" class="'+yesClass+'" onclick="'+callbackYes+';jQuery(\'#'+id+'\').remove(); jQuery(\'#overlay\').fadeOut(\'fast\');"><span>'+yesText+'</span></a><a href="#" class="'+noClass+'" onclick="'+callbackNo+';jQuery(\'#'+id+'\').remove(); jQuery(\'#overlay\').fadeOut(\'fast\');"><span>'+noText+'</span></a></div></td></tr>');
	var warnig = jQuery(html.join("")).draggable();
	jQuery("body").append(warnig);
	jQuery("#overlay").fadeIn('fast');
	return html.join("");
}


function loadChiron(){
    /*if(!width)
    	width = window.innerWidth;
	if(!height)
		height = window.innerHeight;*/
	jQuery('#chironWrapper').attr('height',(window.innerHeight-35));
	jQuery('#chironWrapper').attr('width',window.innerWidth);
}
